home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / nexttsrc.lha / nexttsources / sources / comp / assembler / m68am.t < prev    next >
Encoding:
Text File  |  1988-02-05  |  11.0 KB  |  358 lines

  1. (herald (assembler m68am t 0)
  2.         (env t (assembler as_open)))
  3.  
  4. ;;; Copyright (c) 1985 Yale University
  5. ;;;     Authors: N Adams, R Kelsey, D Kranz, J Philbin, J Rees.
  6. ;;; This material was developed by the T Project at the Yale University Computer 
  7. ;;; Science Department.  Permission to copy this software, to redistribute it, 
  8. ;;; and to use it for any purpose is granted, subject to the following restric-
  9. ;;; tions and understandings.
  10. ;;; 1. Any copy made of this software must include this copyright notice in full.
  11. ;;; 2. Users of this software agree to make their best efforts (a) to return
  12. ;;;    to the T Project at Yale any improvements or extensions that they make,
  13. ;;;    so that these may be included in future releases; and (b) to inform
  14. ;;;    the T Project of noteworthy uses of this software.
  15. ;;; 3. All materials developed as a consequence of the use of this software
  16. ;;;    shall duly acknowledge such use, in accordance with the usual standards
  17. ;;;    of acknowledging credit in academic research.
  18. ;;; 4. Yale has made no warrantee or representation that the operation of
  19. ;;;    this software will be error-free, and Yale is under no obligation to
  20. ;;;    provide any services, by way of maintenance, update, or otherwise.
  21. ;;; 5. In conjunction with products arising from the use of this material,
  22. ;;;    there shall be no use of the name of the Yale University nor of any
  23. ;;;    adaptation thereof in any advertising, promotional, or sales literature
  24. ;;;    without prior written consent from Yale in each case.
  25. ;;;
  26.  
  27. (define (ea-fg ea context)
  28.     (cond ((pair? ea) (ea-fg-1 (car ea) (cdr ea) context))
  29.           (else ea)))
  30.  
  31. (define-fg (ea-fg-1 mode ext context)
  32.     (printer "~g~g" (? mode) (? ext))
  33.     (fg mode context)
  34.     (fg ext context))
  35.  
  36. (define (ea-imm-fg ea imm context)
  37.   (cond ((pair? ea) (ea-imm-fg-2 (car ea) (cdr imm) (cdr ea) context))
  38.         (else (ea-imm-fg-1 ea (cdr imm) context))))
  39.  
  40. (define-fg (ea-imm-fg-1 mode imm context)
  41.     (printer "~g,~g" (? imm) (? mode))
  42.     (fg mode context)
  43.     (fg imm context))
  44.  
  45. (define-fg (ea-imm-fg-2 mode imm ext context)
  46.     (printer "~g,~g~g" (? imm) (? mode) (? ext))
  47.     (fg mode context)
  48.     (fg imm context)
  49.     (fg ext context))
  50.  
  51. ;;; Addressing modes.
  52.  
  53. (define (error-if-not-an an id)
  54.     (cond ((or (fx< an 8) (fx> an 15))
  55.            (error "(~s ~s) -- ~s is not an address register" id an an))))
  56.  
  57. (define (r regnum)
  58.   (vref *register-fgs* regnum))
  59.  
  60. (define d r)
  61. (define (a n) 
  62.     (r (fx+ n 8)))
  63.  
  64. (lset *register-fgs* (make-vector 16))
  65.  
  66. (define (%register regnum)
  67.     (if (fx> regnum 7) (%aregister (fx- regnum 8)) (%dregister regnum)))
  68.  
  69. (define-fg (%aregister regnum)
  70.     (printer "a~s" (? regnum))
  71.     (0 0 1) (f u 3 regnum))
  72.  
  73.  (define %aregister? (fg-predicator %aregister))  
  74.  
  75. (define-fg (%dregister regnum)
  76.     (printer "d~s" (? regnum))
  77.     (0 0 0) (f u 3 regnum))
  78.  
  79.  (define %dregister? (fg-predicator %dregister))  
  80.  
  81. (do ((i 0 (fx+ i 1)))
  82.     ((fx> i 15)
  83.      'done)
  84.   (set (vref *register-fgs* i) (%register i)))
  85.  
  86. (define-fg (@a regnum)
  87.     (printer "(a~s)" (? regnum))
  88.     (0 1 0) (f u 3 regnum))
  89.  
  90.  (define @a? (fg-predicator @a))   ; used by index
  91.  
  92.  (define (@r n) 
  93.      (error-if-not-an n '@r) 
  94.      (@a (fx- n 8)))
  95.  
  96. (define-fg (@a+ regnum)
  97.     (printer "(a~s)+" (? regnum))
  98.     (0 1 1) (f u 3 regnum))
  99.  
  100.  (define @a+? (fg-predicator @a+))   ; used by cmpm.
  101.  
  102.  (define (@r+ n) 
  103.      (error-if-not-an n '@r+) 
  104.      (@a+ (fx- n 8)))
  105.  
  106. (define-fg (@-a regnum)
  107.     (printer "-(a~s)" (? regnum))
  108.     (1 0 0) (f u 3 regnum))
  109.  
  110.  (define @-a? (fg-predicator @-a))   ; used by movem.
  111.  
  112.  (define (@-r n) 
  113.      (error-if-not-an n '@-r) 
  114.      (@-a (fx- n 8)))
  115.                   
  116. (define (d@a regnum displ)
  117.   (cond ((fx= displ 0) (@a regnum))
  118.         (else (%d@a regnum displ))))
  119.  
  120.   (define (d@r n displ) 
  121.       (error-if-not-an n 'd@r) 
  122.       (d@a (fx- n 8) displ))
  123.  
  124. (define (%d@a regnum displ)
  125.     (cons (d@a-bits regnum displ)
  126.           (d@a-ext displ)))
  127.  
  128.   (define-fg (d@a-bits regnum displ)
  129.       (printer "~s(a~s)" (? displ) (? regnum))
  130.       (1 0 1) (f u 3 regnum))
  131.  
  132.   (define d@a-bits? (fg-predicator d@a-bits))   ; used by index
  133.  
  134.   (define-fg (d@a-ext displ)
  135.       (printer "")
  136.       (f s 16 displ))
  137.  
  138.                
  139. ;;; Address register indirect, with diplacement
  140.     
  141. (define (d@ax.w ar xr displ)
  142.     (d@ax ar xr 0 displ))
  143.  
  144. (define (d@ax.l ar xr displ)
  145.     (d@ax ar xr 1 displ))
  146.  
  147.   (define (d@rx.w n x displ) 
  148.       (error-if-not-an n 'd@rx.w) 
  149.       (d@ax.w (fx- n 8) x displ))
  150.  
  151.   (define (d@rx.l n x displ) 
  152.       (error-if-not-an n 'd@rx.l) 
  153.       (d@ax.l (fx- n 8) x displ))
  154.  
  155. (define (d@ax ar xr is-long displ)
  156.     (cons (d@ax-bits ar)
  157.           (d@ax-ext ar xr is-long displ)))
  158.  
  159.   (define-fg (d@ax-bits ar)
  160.       (printer "")
  161.       (1 1 0) (f u 3 ar))
  162.  
  163.   (define-fg (d@ax-ext ar xr is-long displ)
  164.       (printer "~s(a~s,~c~s.~c)" 
  165.                (? displ) 
  166.                (? ar) 
  167.                (if (fx> (? xr) 7) #\a #\d)
  168.                (if (fx> (? xr) 7) (fx- (? xr) 8) xr)
  169.                (if (fx= (? is-long) 1) #\L #\W))
  170.       (f u 4 xr) (f u 1 is-long) (0 0 0) (f s 8 displ))
  171.  
  172. (define (index.w fg xr) (index-1 fg xr 0))
  173. (define (index.l fg xr) (index-1 fg xr 1))
  174. (define index index.l)
  175.  
  176. (define (index-1 fg xr is-long?)
  177.     (cond ((fg? fg)
  178.            (if (not (@a? fg))
  179.                (error "can't index ~s" fg))
  180.            (receive (v w ns) (destructure-fg fg 0)
  181.               (receive (ar w ns) (destructure-fg fg ns)
  182.                  (d@ax ar xr is-long? 0))))
  183.           ((and (pair? fg) (fg? (car fg)) (fg? (cdr fg)))
  184.            (receive (v w ns) (destructure-fg (car fg) 0)
  185.               (receive (ar w ns) (destructure-fg (car fg) ns)
  186.                  (receive (displ w ns) (destructure-fg (cdr fg) 0)
  187.                     (d@ax ar xr is-long? displ)))))
  188.           (else
  189.            (error "can't index ~s" fg))))
  190.  
  191. ;;; Absolute short, missing
  192. ;;; Absolute long, missing
  193.      
  194. ;;; PC relative
  195.  
  196. (define (d@pc tag)
  197.     (cons d@pc-bits
  198.           (d@pc-ext tag)))
  199.  
  200.   (define-fg (d@pc-bits-fg)
  201.        (printer "")
  202.        (1 1 1) (0 1 0))                        
  203.   (define-constant d@pc-bits (d@pc-bits-fg))
  204.  
  205.   (define-fg (d@pc-ext tag)
  206.     (printer "~g" (? tag))
  207.     (local here)
  208.     (mark here)
  209.     (f s 16 (fixnum-ashr (from here tag) 3)))
  210.  
  211. ;;; Indexed PC relative, missing
  212.  
  213. ;;; Immediate
  214.  
  215. (define ($ value)
  216.   (cons &-bits
  217.         (&-ext value)))
  218.  
  219.   (define (&? x) 
  220.     (cond ((and (pair? x) (eq? (car x) &-bits) x)
  221.            x)
  222.           ((fixnum? x)  ; should we be making this for the luser?
  223.            ($ x))
  224.           (else nil)))
  225.  
  226.   (define (&-quick? x)
  227.     (cond ((&? x) 
  228.            (let ((v (fg-argref (cdr x) 0)))
  229.              (quick? v)))   
  230.           ((quick? x))
  231.           (else nil)))
  232.  
  233.   (define-integrable (16bit x) 
  234.     (if (16bit? x) x nil))
  235.                          
  236.   (define (&-word? x)
  237.     (cond ((&? x) 
  238.            (let ((v (fg-argref (cdr x) 0)))
  239.              (16bit v)))
  240.           ((fixnum? x) (16bit x))
  241.           (else nil)))
  242.                             
  243.   (define-integrable (8bit x) 
  244.     (if (8bit? x) x nil))
  245.  
  246.   (define (&-moveq-byte? x)
  247.     (cond ((&? x) 
  248.            (let ((v (fg-argref (cdr x) 0)))
  249.              (8bit v)))
  250.           ((fixnum? x) (8bit x))
  251.           (else nil)))
  252.  
  253.   (define-fg (&-bits-fg)
  254.        (printer "")
  255.        (1 1 1) (1 0 0))
  256.   (define-constant &-bits (&-bits-fg))
  257.  
  258.   (define-fg (&-ext value)
  259.     (context (general size))
  260.     (printer "~g" (? subfg))
  261.     (local subfg)
  262.     (fg-named subfg (choose-imm-fg (? size) (? value)) #f))
  263.  
  264.   (define (choose-imm-fg size value)
  265.     (xcond ((fx= size 8) (&-8 value))
  266.            ((or (fx= size 16) (fx= size 32)) (&-16-or-32 size value))))
  267.  
  268.   (define-fg (&-8 value)
  269.      (printer "#~s.B" (? value))
  270.      (0 0 0 0 0 0 0 0) (f s 8 value))
  271.   
  272.   (define-fg (&-16-or-32 size value)
  273.      (printer "#~s.~c" (? value) (if (fx= (? size) 16) #\W #\L))
  274.      (f s size value))
  275.  
  276. ;;; This is here just so recompiling is quicker, ought to be in ...is
  277.  
  278. ;;; -------------------------- Template stuff.
  279.  
  280. ;       3                   2                   1
  281. ;     1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
  282. ;    |                              ...                              |
  283. ;    +-------------------------------+-------------------------------+
  284. ;    |       annotation offset       |  handler's jump displacement  |
  285. ;    +---------------+---------------+-------------------------------+
  286. ;    |  # ptr cells  |  # scr cells  |    offset within bit vector   |
  287. ;    +-+-+-----------+---------------+-------------------------------+
  288. ;    |1|N|unused     |   # of args   |  instructions ---->>          | <--- ptr
  289. ;    +-+-+-----------+---------------+                               |
  290. ;    |                      instruction stream                       |
  291. ;    |                              ...                              |
  292.  
  293. ;;; these fields are in the wrong order.
  294.  
  295. (define-data-fg (m68/template lambda-node handler-ib)
  296. ;    (printer ".tem    ~s,~g" (? lambda-node) (? handler-ib))
  297.     (printer ".template")
  298.     (local template-end)
  299.     (f u 16 (get-template-annotation (? lambda-node)))        
  300.     ;;handler offset
  301.     (f s 16 (fixnum-ashr (from template-end handler-ib) 3))   
  302.     (f u 16 (get-template-cells (? lambda-node)))
  303.     ;;bitv offset
  304.     (f u 16 (fx+ (fixnum-ashr (mark-address (? template-end)) 3) 2)) 
  305.     (1)
  306.     (f u 1 (if (template-nary (? lambda-node))  1 0))
  307.     (f u 6 0)
  308.     (f u 8 (get-template-nargs (? lambda-node)))
  309.     (mark template-end)
  310.     )
  311.  
  312. (define (emit-m68-template code-node code-ib handler-ib template-ib)
  313.    (set (ib-align template-ib) '(24 31 0))
  314.    (emit-to-ib template-ib (m68/template code-node handler-ib))
  315.    (set-ib-follower template-ib code-ib)
  316.    )
  317.  
  318. ;;; Floating point bit fields.
  319.  
  320. ;;; <n,s> means bit field of length s beginning at bit n of the first
  321. ;;; WORD (not longword)
  322. ;;;                    sign      exponent   MSB       fraction
  323. ;;; Apollo IEEE flonum <15,1>    <4,11>     hidden    <0,4>+next 3 words
  324. ;;; VAX11 flonum (D)   <15,1>    <7,8>      hidden    <0,7>+next 3 words
  325. ;;; Apollo IEEE flonum - binary point follows  hidden MSB, 53 bits of
  326. ;;;     precision, if hidden bit is included
  327. ;;; VAX11 flonum (D)   - binary point precedes hidden MSB, 56 bits of
  328. ;;;     precision, if hidden bit is included 
  329.  
  330. ;;; On the vax
  331. ;;;   (integer-decode-float 1.0 list) =>
  332. ;;;     (36028797018963968 -55)
  333. ;;;     actual stored exponent is 129
  334.  
  335. ;;; On the Apollo
  336. ;;;   (integer-decode-float 1.0 list)
  337. ;;;     (4503599627370496 -52)
  338. ;;;     actual stored exponent is 1023
  339.  
  340. (define-constant %%apollo-d-ieee-size 53)
  341. (define-constant %%apollo-d-ieee-excess 1023)
  342.  
  343. (define (apollo-d-ieee-floating-bits flonum)
  344.    (receive (s nm ne)
  345.             (normalized-float-parts flonum 
  346.                                     %%apollo-d-ieee-size 
  347.                                     %%apollo-d-ieee-excess 
  348.                                     t)
  349.       (apollo-d-ieee-floating-fg flonum s nm ne)))
  350.  
  351. (define-data-fg (apollo-d-ieee-floating-fg flonum s m e)
  352.     (printer ".dfloat ~s" (? flonum))
  353.     (f u 1 s) (f u 11 e) (f u 4  (bignum-bit-field (? m) 48 4))
  354.     (f u 16 (bignum-bit-field (? m) 32 16))
  355.     (f u 16 (bignum-bit-field (? m) 16 16))
  356.     (f u 16 (bignum-bit-field (? m) 0  16)))
  357.  
  358.